package org.csu.webjpetstoreback.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.csu.webjpetstoreback.config.CommonResponse;
import org.csu.webjpetstoreback.mapper.CategoryMapper;
import org.csu.webjpetstoreback.mapper.LineItemsMapper;
import org.csu.webjpetstoreback.mapper.OrdersMapper;
import org.csu.webjpetstoreback.model.Category;
import org.csu.webjpetstoreback.model.LineItem;
import org.csu.webjpetstoreback.service.CategoryService;
import org.csu.webjpetstoreback.service.LineItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    public CategoryMapper categoryMapper;

    @Override
    public CommonResponse<Category> GetCategoryById(String categoryId) {
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("categoryid",categoryId);
        Category category = categoryMapper.selectOne(queryWrapper);
        if (category!=null){
            return CommonResponse.BackForSuccess(category);
        }else {
            return CommonResponse.BackForError("该category不存在");
        }
    }

    @Override
    public CommonResponse<List<Category>> GetCategoryList() {
        List<Category> categoryList=categoryMapper.selectList(null);
        if(categoryList.size()>0)
        {
            return CommonResponse.BackForSuccess(categoryList);
        }else {
            return CommonResponse.BackForError("miucategory");
        }
    }
}
